package com.iptv.grape.net.Entity;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.iptv.grape.domain.Channel;
import com.iptv.grape.domain.ChannelType;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.util.ReadJsonFile;

import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;

// 频道信息传输模型
public class ChannelData {
    // 频道ID
    private String keyID;
    // 频道号
    private String channelNo;
    // 频道名称
    private String name;
    // 频道简称
    private String sName;
    // 别名
    private String alName;
    // 图标地址
    private String logo;
    // 直播播放地址(单播地址)
    private String uAddress;
    // 直播播放地址(组播地址)
    private String mAddress;
    // 回看单播地址
    private String ruAddress;
    // 回看组播地址
    private String rmAddress;

    public String getKeyID() {
        return keyID;
    }

    public void setKeyID(String keyID) {
        this.keyID = keyID;
    }

    public String getChannelNo() {
        return channelNo;
    }

    public void setChannelNo(String channelNo) {
        this.channelNo = channelNo;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getsName() {
        return sName;
    }

    public void setsName(String sName) {
        this.sName = sName;
    }

    public String getAlName() {
        return alName;
    }

    public void setAlName(String alName) {
        this.alName = alName;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public String getuAddress() {
        return uAddress;
    }

    public void setuAddress(String uAddress) {
        this.uAddress = uAddress;
    }

    public String getmAddress() {
        return mAddress;
    }

    public void setmAddress(String mAddress) {
        this.mAddress = mAddress;
    }

    public String getRuAddress() {
        return ruAddress;
    }

    public void setRuAddress(String ruAddress) {
        this.ruAddress = ruAddress;
    }

    public String getRmAddress() {
        return rmAddress;
    }

    public void setRmAddress(String rmAddress) {
        this.rmAddress = rmAddress;
    }

    public String getTuAddress() {
        return tuAddress;
    }

    public void setTuAddress(String tuAddress) {
        this.tuAddress = tuAddress;
    }

    public String getTmAddress() {
        return tmAddress;
    }

    public void setTmAddress(String tmAddress) {
        this.tmAddress = tmAddress;
    }

    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    public String getCategoryCode() {
        return categoryCode;
    }

    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
    }

    public String getSiteCode() {
        return siteCode;
    }

    public void setSiteCode(String siteCode) {
        this.siteCode = siteCode;
    }

    // 时移单播地址
    private String tuAddress;
    // 时移组播地址
    private String tmAddress;
    // 排序
    private int sort;
    // 频道分类编码
    private String categoryCode;
    // 站点编码
    private String siteCode;


    public static void serializeToFile(List<ChannelData> channelDataList){
        Gson gson = new Gson();
        String json = gson.toJson(channelDataList);
        ReadJsonFile.writeFile("channelData.json",json);
        AppLog.getCurLog().out("保存频道列表到文件");
    }

    public static List<ChannelData> unSerializeToFile(){
        List<ChannelData> channelDataList = null;
        try {
            String json = ReadJsonFile.readFile("channelData.json");
            Type type = new TypeToken<List<ChannelData>>() {}.getType();
            channelDataList = new Gson().fromJson(json, type);
        }
        catch (Exception ex){
            ex.printStackTrace();
        }
        return channelDataList;
    }
}
